﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace lin_cms_dotnet_core.Models
{
    public partial class AppDbContext : DbContext
    {

        public AppDbContext(DbContextOptions<AppDbContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Book> Books { get; set; }
        public virtual DbSet<Flow> Flows { get; set; }
        public virtual DbSet<LinFile> LinFiles { get; set; }
        public virtual DbSet<LinGroup> LinGroups { get; set; }
        public virtual DbSet<LinGroupPermission> LinGroupPermissions { get; set; }
        public virtual DbSet<LinLog> LinLogs { get; set; }
        public virtual DbSet<LinPermission> LinPermissions { get; set; }
        public virtual DbSet<LinUser> LinUsers { get; set; }
        public virtual DbSet<LinUserGroup> LinUserGroups { get; set; }
        public virtual DbSet<LinUserIdentity> LinUserIdentities { get; set; }
        public virtual DbSet<Movie> Movies { get; set; }
        public virtual DbSet<Music> Musics { get; set; }
        public virtual DbSet<Sentence> Sentences { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseMySql("server=localhost;user=root;password=root;database=lin-cms;treattinyasboolean=false", Microsoft.EntityFrameworkCore.ServerVersion.Parse("10.1.37-mariadb"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasCharSet("utf8mb4")
                .UseCollation("utf8mb4_general_ci");

            modelBuilder.Entity<Book>(entity =>
            {
                entity.Property(e => e.CreateTime).HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.UpdateTime)
                    .ValueGeneratedOnAddOrUpdate()
                    .HasDefaultValueSql("CURRENT_TIMESTAMP(3)");
            });

            modelBuilder.Entity<Flow>(entity =>
            {
                entity.UseCollation("utf8mb4_bin");
            });

            modelBuilder.Entity<LinFile>(entity =>
            {
                entity.Property(e => e.CreateTime).HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.Md5).HasComment("md5值，防止上传重复文件");

                entity.Property(e => e.Type)
                    .HasDefaultValueSql("'LOCAL'")
                    .HasComment("LOCAL 本地，REMOTE 远程");

                entity.Property(e => e.UpdateTime)
                    .ValueGeneratedOnAddOrUpdate()
                    .HasDefaultValueSql("CURRENT_TIMESTAMP(3)");
            });

            modelBuilder.Entity<LinGroup>(entity =>
            {
                entity.Property(e => e.CreateTime).HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.Info).HasComment("分组信息：例如：搬砖的人");

                entity.Property(e => e.Level)
                    .HasDefaultValueSql("'3'")
                    .HasComment("分组级别 1：root 2：guest 3：user（root、guest分组只能存在一个)");

                entity.Property(e => e.Name).HasComment("分组名称，例如：搬砖者");

                entity.Property(e => e.UpdateTime)
                    .ValueGeneratedOnAddOrUpdate()
                    .HasDefaultValueSql("CURRENT_TIMESTAMP(3)");
            });

            modelBuilder.Entity<LinGroupPermission>(entity =>
            {
                entity.Property(e => e.GroupId).HasComment("分组id");

                entity.Property(e => e.PermissionId).HasComment("权限id");
            });

            modelBuilder.Entity<LinLog>(entity =>
            {
                entity.Property(e => e.CreateTime).HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.UpdateTime)
                    .ValueGeneratedOnAddOrUpdate()
                    .HasDefaultValueSql("CURRENT_TIMESTAMP(3)");
            });

            modelBuilder.Entity<LinPermission>(entity =>
            {
                entity.Property(e => e.CreateTime).HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.Module).HasComment("权限所属模块，例如：人员管理");

                entity.Property(e => e.Mount)
                    .HasDefaultValueSql("'1'")
                    .HasComment("0：关闭 1：开启");

                entity.Property(e => e.Name).HasComment("权限名称，例如：访问首页");

                entity.Property(e => e.UpdateTime)
                    .ValueGeneratedOnAddOrUpdate()
                    .HasDefaultValueSql("CURRENT_TIMESTAMP(3)");
            });

            modelBuilder.Entity<LinUser>(entity =>
            {
                entity.Property(e => e.Avatar).HasComment("头像url");

                entity.Property(e => e.CreateTime).HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.Email).HasComment("邮箱");

                entity.Property(e => e.Nickname).HasComment("用户昵称");

                entity.Property(e => e.UpdateTime)
                    .ValueGeneratedOnAddOrUpdate()
                    .HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.Username).HasComment("用户名，唯一");
            });

            modelBuilder.Entity<LinUserGroup>(entity =>
            {
                entity.Property(e => e.GroupId).HasComment("分组id");

                entity.Property(e => e.UserId).HasComment("用户id");
            });

            modelBuilder.Entity<LinUserIdentity>(entity =>
            {
                entity.Property(e => e.CreateTime).HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.UpdateTime)
                    .ValueGeneratedOnAddOrUpdate()
                    .HasDefaultValueSql("CURRENT_TIMESTAMP(3)");

                entity.Property(e => e.UserId).HasComment("用户id");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
